﻿
using System;
using SmallShop.Frame;
using SmalShop.Model;

namespace SmallShop.Bll
{
    public class BannerBiz: BaseBiz<BannerModel>
    {
        public override ResultModel Add(BannerModel model)
        {
            string msg;
            if (!CheckModel(model, out msg))
            {
                return new ResultModel {Code = ResultModel.InValid, Message = msg};
            }
            return base.Add(model);
        }

        public override ResultModel Update(BannerModel model)
        {
            var msg ="无效的更改数据";
            if ( model.Id < 1 || !CheckModel(model, out msg))
            {
                return new ResultModel { Code = ResultModel.InValid, Message = msg };
            }
            return base.Update(model);
        }

        public static bool CheckModel(BannerModel model, out string msg)
        {
            msg = null;
            if (model.Title.IsNullOrEmpty())
            {
                msg = "无效的名称";
                return false;
            }
            if (model.Url.IsNullOrEmpty())
            {
                msg = "无效的跳转链接";
                return false;
            }
            if (model.ImgUrl.IsNullOrEmpty())
            {
                msg = "无效的图片路径";
                return false;
            }
            if (model.StartTime == DateTime.MinValue)
            {
                msg = "无效的开始时间";
                return false;
            }
            if (model.EndTime == DateTime.MinValue)
            {
                msg = "无效的开始结束";
                return false;
            }
            return true;
        }
    }
}
